/*
 *   This program is free software: you can redistribute it and/or modify
 *   it under the terms of the GNU General Public License as published by
 *   the Free Software Foundation, either version 3 of the License, or
 *   (at your option) any later version.
 *
 *   This program is distributed in the hope that it will be useful,
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *   GNU General Public License for more details.
 *
 *   You should have received a copy of the GNU General Public License
 *   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */

/*
 * SerializedParameterMapReader.java
 * Copyright (C) 2019 University of Waikato, Hamilton, NZ
 */

package adams.data.io.input;

import adams.core.SerializationHelper;
import adams.core.io.PlaceholderFile;

import java.util.Map;

/**
 * Reads a parameter map from a serialized file.
 *
 * @author FracPete (fracpete at waikato dot ac dot nz)
 */
public class SerializedParameterMapReader
  extends AbstractParameterMapReader {

  private static final long serialVersionUID = 9004360307036373441L;

  /**
   * Returns a string describing the object.
   *
   * @return 			a description suitable for displaying in the gui
   */
  @Override
  public String globalInfo() {
    return "Reads a parameter map from a serialized file.";
  }

  /**
   * Returns a string describing the format (used in the file chooser).
   *
   * @return 			a description suitable for displaying in the
   * 				file chooser
   */
  @Override
  public String getFormatDescription() {
    return "Serialized map";
  }

  /**
   * Returns the extension(s) of the format.
   *
   * @return 			the extension (without the dot!)
   */
  @Override
  public String[] getFormatExtensions() {
    return new String[]{"ser"};
  }

  @Override
  public String getDefaultFormatExtension() {
    return "ser";
  }

  /**
   * Returns the default extension of the format.
   *
   * @return 			the default extension (without the dot!)
   */
  @Override
  protected Map<String, Object> doRead(PlaceholderFile input) throws Exception {
    return (Map<String, Object>) SerializationHelper.read(input.getAbsolutePath());
  }
}
